﻿using Manager.Database;
using Manager.Model;

namespace Manager.Service
{
    public class ArticleService
    {

        private readonly PCCSContext _context;

        public ArticleService(PCCSContext context)
        {
            _context = context;
        }

        public void AddArticle(Article article)
        {
            _context.articles.Add(article);
            _context.SaveChanges();
        }

        public void UpdateArticle(Article article)
        {
            _context.articles.Update(article);
            _context.SaveChanges();
        }

        public List<Article> GetArticles()
        {
            return _context.articles.ToList();
        }


        public void DeleteArticle(int id)
        {
            var article = _context.articles.Find(id);
            _context.articles.Remove(article);
            _context.SaveChanges();
        }

        public Article GetArticleById(int id)
        {
            var data = _context.articles.Find(id);
            return data;
        }
    }
}
